package Control;

import java.util.Date;

import javax.swing.JOptionPane;

import Entity.NeedyResident_CreateAccount;
import Entity.NeedyResident_UpdateAccount;
import Form.NeedyResident_UpdateUser_Form;

public class NeedyResident_UpdateUser_Control {
	
	private NeedyResident_UpdateUser_Form parser;
	
	public NeedyResident_UpdateUser_Form getParser() {
		return parser;
	}

	public void setPaser(NeedyResident_UpdateUser_Form parser) {
		this.parser = parser;
	}

	NeedyResident_UpdateAccount resident = new NeedyResident_UpdateAccount();
	
	public NeedyResident_UpdateUser_Control(NeedyResident_UpdateUser_Form parser){
		this.setPaser(parser);
		
	}
	
	public NeedyResident_UpdateAccount UpdateUser(){
		resident.setNric(getParser().getLbl_nric().getText());
		resident.setPassword(new String((getParser().getPf_newpassword().getPassword())));
		resident.setContact_no(Integer.parseInt(getParser().getTf_contactNo().getText()));
		resident.setEmail(getParser().getTf_email().getText());
		//How to get Text
		resident.setAddress(getParser().getTf_address().getText());
		//How to get Double
		resident.setMonthlySalary(Double.parseDouble(getParser().getTf_monthlyIncome().getText()));
		resident.setFamilySize(Integer.parseInt(getParser().getTf_familySize().getText()));
		
		boolean success = resident.UpdateNeedyResident();
		
		if (success == true)
			JOptionPane.showMessageDialog(null, "Account Successfully Updated!");
		else
			JOptionPane.showMessageDialog(null, "Error encountered, please try again");
		
		return resident;
	}
}
